package com.example.site.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.util.SaResult;
import com.example.site.entity.Order;
import com.example.site.entity.Room;
import com.example.site.service.OrderService;
import com.example.site.service.TypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/web")
public class WebController {
    @Resource
    TypeService typeService;
    @Resource
    OrderService orderService;

    /**
     * @param
     * @return
     * @deprecated 获取所有房间类型
     */
    @GetMapping("/rooms")
    public SaResult rooms() {
        return typeService.getAll();
    }

    /**
     * @param
     * @return
     * @deprecated 获取房间详情
     */
    @GetMapping("/room-detail/{id}")
    public SaResult roomDetail(@PathVariable Integer id) {
        return typeService.getDetail(id);
    }


    /**
     * @param
     * @return
     * @deprecated 创建订单
     */
    @SaCheckLogin
    @PostMapping("/create-order/")
    public SaResult createOrder(@RequestBody Order order) {
        return orderService.createOrder(order);
    }

    /**
     * @param
     * @return
     * @deprecated 获取我的预约订单
     */
    @SaCheckLogin
    @GetMapping("/my-order")
    public SaResult myOrder() {
        return orderService.getMyOrderJoinType();
    }

    @SaCheckLogin
    @PostMapping("/cancel-order/{id}")
    public SaResult cancelOrder(@PathVariable Integer id) {
        return orderService.cancelOrder(id);
    }


}
